<template>
	<view>
		<view class="pagenation">
			<view class="pagenation_title">
				订单
			</view>
		</view>

		<view class="tabs">
			<view class="tab" v-for="(item,index) in tabs" :key="index"
				:class="orderStatus === item.status?'active':''">
				{{item.name}}
				<view class="tab_line"></view>
			</view>
		</view>

		<view class="order_list">
			<view class="order_item" v-for="(item,index) in orderList" :key="index">
				<view class="order_item_hd" @tap="toOrderDetail(item)">
					<view class="order_store_img">
						<image :src="item.storePic" mode="aspectFill"></image>
					</view>
					<view class="order_store_info">
						<view class="order_store_name">
							{{item.storeName}}
						</view>
						<view class="order_time">
							{{item.time}}
						</view>
					</view>
					<view class="order_orderStatus">
						{{item.orderStatus == 1?'待支付':item.orderStatus == 2?'待收货':item.orderStatus == 3?'待评价':item.orderStatus == 4?'已完成':'已取消'}}
					</view>
				</view>
				<view class="order_item_bd" @tap="toOrderDetail(item)">
					<view class="order_goods">
						<view class="order_good" v-for="(item2,index2) in item.list" :key="index2 + 10">
							<view class="order_good_img">
								<image :src="item2.picUrl" mode=""></image>
							</view>
							<view class="order_good_name">
								{{item2.name}}
							</view>
						</view>
					</view>
					<view class="order_other">
						<view class="order_price">
							¥{{item.totalPirce}}
						</view>
						<view class="order_number">
							共{{item.number}}件
						</view>
					</view>
				</view>
				<view class="order_item_bt">
					<view class="order_item_cancel" v-if="item.orderStatus == 1 || item.orderStatus == 2"
						@tap="cancelOrder(item)">
						取消订单
					</view>
					<view class="order_item_cancel"
						v-if="item.orderStatus == 3 || item.orderStatus == 4 || item.orderStatus == 5">
						查看详情
					</view>
					<view class="order_item_pay" v-if="item.orderStatus == 1">
						进行支付
					</view>
					<view class="order_item_pay" v-if="item.orderStatus == 2">
						确认收货
					</view>
					<view class="order_item_pay" v-if="item.orderStatus == 3" @tap="toEvaluate(item)">
						晒单评价
					</view>

				</view>
			</view>
		</view>

		<view class="mask" v-if="cancelFlag == true">

		</view>
		<view class="cancel_mask" v-if="cancelFlag == true">
			<view class="delete_title">
				确定要取消该订单吗？
			</view>
			<view class="delete_btns">
				<view class="delete_cancel" @tap="cancelDelete()">
					取消
				</view>
				<view class="delete_sure" @tap="sureDelete()">
					确定
				</view>
			</view>
		</view>

		<tabBar current="2" v-show="cancelFlag != true"></tabBar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderStatus: '',
				tabs: [{
						name: '全部',
						status: ''
					},
					{
						name: '待支付',
						status: '1'
					},
					{
						name: '待收货',
						status: '2'
					},
					{
						name: '待评价',
						status: '3'
					},
					{
						name: '已完成',
						status: '4'
					},
					{
						name: '已取消',
						status: '5'
					}
				],
				orderList: [{
						storePic: require('../../static/image/order/order_1.jpg'),
						storeName: '于新四季福火锅冒菜...',
						time: '2021-05-01 11:46',
						totalPirce: '16.48',
						number: 3,
						orderStatus: 1,
						list: [{
								picUrl: require('../../static/image/order/order_11.jpg'),
								name: '金汤肥牛锅（口...'
							},
							{
								picUrl: require('../../static/image/order/order_12.jpg'),
								name: '麻辣锅（口味辣...'
							},
							{
								picUrl: require('../../static/image/order/order_13.jpg'),
								name: '肥牛卷（切片装...'
							}
						]
					},
					{
						storePic: require('../../static/image/order/order_2.jpg'),
						storeName: '马尔丹披萨店',
						time: '2021-05-01 11:46',
						totalPirce: '16.8',
						number: 2,
						orderStatus: 2,
						list: [{
								picUrl: require('../../static/image/order/order_21.jpg'),
								name: '水果披萨切（口...'
							},
							{
								picUrl: require('../../static/image/order/order_22.jpg'),
								name: '肉质披萨切（口...'
							}
						]
					},
					{
						storePic: require('../../static/image/order/order_2.jpg'),
						storeName: '马尔丹披萨店',
						time: '2021-05-01 11:46',
						totalPirce: '16.8',
						number: 2,
						orderStatus: 3,
						list: [{
								picUrl: require('../../static/image/order/order_21.jpg'),
								name: '水果披萨切（口...'
							},
							{
								picUrl: require('../../static/image/order/order_22.jpg'),
								name: '肉质披萨切（口...'
							}
						]
					},
					{
						storePic: require('../../static/image/order/order_1.jpg'),
						storeName: '于新四季福火锅冒菜...',
						time: '2021-05-01 11:46',
						totalPirce: '16.48',
						number: 3,
						orderStatus: 4,
						list: [{
								picUrl: require('../../static/image/order/order_11.jpg'),
								name: '金汤肥牛锅（口...'
							},
							{
								picUrl: require('../../static/image/order/order_12.jpg'),
								name: '麻辣锅（口味辣...'
							},
							{
								picUrl: require('../../static/image/order/order_13.jpg'),
								name: '肥牛卷（切片装...'
							}
						]
					},
					{
						storePic: require('../../static/image/order/order_1.jpg'),
						storeName: '于新四季福火锅冒菜...',
						time: '2021-05-01 11:46',
						totalPirce: '16.48',
						number: 3,
						orderStatus: 5,
						list: [{
								picUrl: require('../../static/image/order/order_11.jpg'),
								name: '金汤肥牛锅（口...'
							},
							{
								picUrl: require('../../static/image/order/order_12.jpg'),
								name: '麻辣锅（口味辣...'
							},
							{
								picUrl: require('../../static/image/order/order_13.jpg'),
								name: '肥牛卷（切片装...'
							}
						]
					},
				],
				cancelFlag: false
			};
		},
		methods: {
			cancelDelete() {
				this.cancelFlag = false;
			},

			sureDelete() {
				this.cancelFlag = false;
				uni.showToast({
					title: "取消成功",
					icon: 'none',
					duration: 2000
				})
			},

			cancelOrder(item) {
				this.cancelFlag = true;
			},
			
			toOrderDetail(item){
				uni.navigateTo({
					url:'/pages/order/detail'
				})
			},
			toEvaluate(item){
				uni.navigateTo({
					url:'/pages/order/evaluate'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F9FBFC;
	}

	.pagenation {
		padding: 60rpx 24rpx 0;

		.pagenation_title {
			text-align: center;
			font-size: 36rpx;
			color: #333;
			font-weight: bolder;
		}
	}

	.tabs {
		padding: 0 24rpx;
		display: flex;
		justify-content: space-between;
		padding-top: 40rpx;

		.tab {
			position: relative;
			color: #666666;
			font-size: 28rpx;
			padding-bottom: 16rpx;

			&.active {
				color: #2588FF;
				font-weight: bolder;

				.tab_line {
					display: block;
				}
			}

			.tab_line {
				display: none;
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				height: 4rpx;
				background-color: #2588FF;
			}
		}
	}

	.order_list {
		margin-top: 30rpx;
		padding: 0 24rpx;
		padding-bottom: 180rpx;

		.order_item {
			background-color: #fff;
			padding: 0 24rpx;
			margin-bottom: 30rpx;

			.order_item_hd {
				position: relative;
				padding: 32rpx 0;
				display: flex;
				align-items: center;

				.order_store_img {
					width: 100rpx;
					height: 100rpx;
					flex-shrink: 0;

					image {
						width: 100rpx;
						height: 100rpx;
						border-radius: 8rpx;
					}
				}

				.order_store_info {
					margin-left: 15rpx;

					.order_store_name {
						font-size: 30rpx;
						font-weight: bolder;
						color: #2E343A;
					}

					.order_time {
						margin-top: 6rpx;
						color: #9098A0;
						font-size: 24rpx;
					}
				}

				.order_orderStatus {
					position: absolute;
					right: 0;
					font-size: 28rpx;
					color: #666666;
				}
			}

			.order_item_bd {
				position: relative;

				.order_goods {
					display: flex;

					.order_good {
						display: flex;
						flex-direction: column;
						align-items: center;
						margin-right: 10rpx;

						.order_good_img {
							width: 170rpx;
							height: 116rpx;

							image {
								width: 100%;
								height: 100%;
								border-radius: 8rpx;
							}
						}

						.order_good_name {
							color: #666666;
							font-size: 20rpx;
						}
					}
				}

				.order_other {
					position: absolute;
					right: 0;
					top: 50%;
					transform: translateY(-80%);
					display: flex;
					flex-direction: column;
					align-items: center;

					.order_price {
						font-size: 32rpx;
						color: #000000;
						font-weight: 500;
					}

					.order_number {
						font-size: 24rpx;
						color: #666666;
					}
				}
			}

			.order_item_bt {
				padding: 32rpx 0;
				display: flex;
				justify-content: flex-end;

				.order_item_cancel {
					width: 156rpx;
					height: 56rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					border: 1rpx solid #D8D8D8;
					font-size: 26rpx;
					color: #2E343A;
					border-radius: 5rpx;
				}

				.order_item_pay {
					width: 156rpx;
					height: 56rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					background-color: #2588FF;
					font-size: 26rpx;
					color: #fff;
					border-radius: 5rpx;
					margin-left: 20rpx;
				}
			}
		}
	}

	.mask {
		position: fixed;
		z-index: 5;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.5);
	}

	.cancel_mask {
		position: fixed;
		z-index: 5;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		width: 610rpx;
		height: 300rpx;
		background-color: #fff;
		padding-top: 80rpx;
		border-radius: 12rpx;

		.delete_title {
			text-align: center;
			color: #2E343A;
			font-size: 32rpx;
			font-weight: 500;
		}

		.delete_btns {
			position: absolute;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 96rpx;
			border-top: 1rpx solid #ccc;
			display: flex;

			.delete_cancel {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 50%;
				height: 96rpx;
				color: #2E343A;
				border-right: 1rpx solid #ccc;
			}

			.delete_sure {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 50%;
				height: 96rpx;
				color: #2588FF;
			}
		}
	}
</style>